package com.ryhx.wifi.base.model.newsinfo.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import com.ryhx.osp.common.page.MysqlPageBean;
import com.ryhx.wifi.facade.base.entity.NewsInfo;
import com.ryhx.wifi.base.model.newsinfo.dao.NewsInfoDao;
import com.ryhx.wifi.base.model.newsinfo.service.NewsInfoService;
import com.ryhx.wifi.common.exceptions.BizException;

@Component("newsInfoService")
public class NewsInfoServiceImpl implements NewsInfoService {
	@Resource(name = "newsInfoDao")
	private NewsInfoDao newsInfoDao;

	@Override
	public NewsInfo getNewsInfo(Long entityId) throws BizException {
		Map<String, Object> query = new HashMap<String, Object>();
		query.put("entityId", entityId);
		return newsInfoDao.getNewsInfo(query);
	}

	@Override
	public List<NewsInfo> getNewsInfoList(NewsInfo newsInfo, MysqlPageBean pageBean) throws BizException {
		return newsInfoDao.getNewsInfoList(newsInfo, pageBean);
	}

	@Override
	public Integer getNewsInfoListCount(NewsInfo newsInfo) throws BizException {
		return newsInfoDao.getNewsInfoListCount(newsInfo);
	}

	@Override
	public List<NewsInfo> getNewsInfoListByParams(Map<String, Object> params) throws BizException {
		return newsInfoDao.getNewsInfoListByParams(params);
	}

	@Override
	public Integer getNewsInfoListCountByParams(Map<String, Object> params) throws BizException {
		return newsInfoDao.getNewsInfoListCountByParams(params);
	}

	@Override
	public Long insertNewsInfo(NewsInfo newsInfo) throws BizException {
		return newsInfoDao.insertNewsInfo(newsInfo);
	}

	@Override
	public int updateNewsInfo(NewsInfo newsInfo) throws BizException {
		return newsInfoDao.updateNewsInfo(newsInfo);
	}

	@Override
	public int updateNewsInfoWithoutNull(NewsInfo newsInfo) throws BizException {
		return newsInfoDao.updateNewsInfoWithoutNull(newsInfo);
	}

	@Override
	public int updateNewsInfoByWhereSql(Map<String, Object> newsInfo, String whereSql) throws BizException {
		if (newsInfo == null || newsInfo.isEmpty()) {
			throw new RuntimeException("newsInfo不能为空");
		}
		if (StringUtils.isBlank(whereSql)) {
			throw new RuntimeException("whereSql不能为空");
		}
		newsInfo.put("whereSql", whereSql);
		return newsInfoDao.updateNewsInfoByWhereSql(newsInfo);
	}

	@Override
	public int deleteNewsInfo(Long entityId) throws BizException {
		Map<String, Object> query = new HashMap<String, Object>();
		query.put("entityId", entityId);
		return newsInfoDao.deleteNewsInfo(query);
	}

	@Override
	public int deleteNewsInfoList(Map<String, Object> newsInfo) throws BizException{
		return newsInfoDao.deleteNewsInfoList(newsInfo);
	}

	@Override
	public int deleteNewsInfoByWhereSql(String whereSql) throws BizException {
		if (StringUtils.isBlank(whereSql)) {
			throw new RuntimeException("whereSql不能为空");
		}
		Map<String, Object> query = new HashMap<String, Object>();
		query.put("whereSql", whereSql);
		return newsInfoDao.deleteNewsInfoByWhereSql(query);
	}

	@Override
	public int truncateNewsInfo() throws BizException {
		return newsInfoDao.truncateNewsInfo();
	}

	@Override
	public int batchInsertNewsInfo(List<NewsInfo> newsInfoList) throws BizException {
		return newsInfoDao.batchInsertNewsInfo(newsInfoList);
	}

	@Override
	public int batchUpdateNewsInfo(List<NewsInfo> newsInfoList) throws BizException {
		return newsInfoDao.batchUpdateNewsInfo(newsInfoList);
	}

	@Override
	public int batchDeleteNewsInfo(List<Long> idList) throws BizException {
		return newsInfoDao.batchDeleteNewsInfo(idList);
	}

	@Override
	public int batchDeleteNewsInfoList(List<NewsInfo> newsInfoList) throws BizException{
		return newsInfoDao.batchDeleteNewsInfoList(newsInfoList);
	}
}
